<?php
$username = $_POST['username'];
$password = $_POST['password'];
$pwd=$_POST['pwd'];
$nickname=$_POST['nickname'];
if (!preg_match("/^\w{3,20}@\w{2,6}\.[a-zA-Z\.]{2,6}$/", $username)) {
    exit('<script>alert("账号规则错误！")</script>');
}
if (!preg_match("/^\w{6,18}$/", $password)) {
    exit('<script>alert("密码规则错误！")</script>');
}
if ($password != $pwd) {
    exit('<script>alert("密码不一致！")</script>');
}
//if (!preg_match("/^\w{4,12}$/", $nickname)) {
//    exit('<script>alert("昵称规则错误！")</script>');
//}
//打开数据库连接('主机名或 IP 地址'，'MySQL 用户名','MySQL 密码','数据库名')
$sql = mysqli_connect('localhost', 'wd', '123456', 'wd');
//判断是否连接mysql
 if (!$sql) {
      die("连接数据失败！");
    }
    
 
//(变量,"mysql增加语句values(?,?)")
    
$stmt = mysqli_prepare($sql, "insert into register(`username`,`password`,nickname)values(?,?,?)");
//(变量,'列名有几个写几个',变量,变量)
   $b=md5($password);
mysqli_stmt_bind_param($stmt, 'sss', $username,$b,$nickname);
//执行语句

if (mysqli_stmt_execute($stmt)) {
        echo "添加成功！";
    }else{
        echo "添加失败！";
    }
//关闭数据库连接
mysqli_close($sql);


